import { RequestConfig } from 'umi';
import { message } from 'antd';
import { createLogger } from 'redux-logger';
export const request: RequestConfig = {
  timeout: 1000,
  errorConfig: {},
  middlewares: [],
  requestInterceptors: [
    (url, options) => {
      console.log('options...', options);
      return {
        url: url,
        options: {
          ...options,
          interceptors: true,
        },
      };
    },
  ],
  responseInterceptors: [
    (response) => {
      const codeMaps: { [key: number]: string } = {
        401: '鉴权失败',
        404: '请求接口不存在',
        502: '网关错误',
        503: '服务不可用，服务器暂时过载或维护',
        504: '网关超时',
      };
      if (response.status !== 200) {
        message.error(codeMaps[response.status]);
      }
      return response;
    },
  ],
};
export const dva = {
  config: {
    onAction: createLogger(),
    onError(e: Error) {
      message.error(e.message, 3);
    },
  },
};
